//
//  ChooseImageCell.m
//  XDBaseFrameWork
//
//  Created by xindao on 14-9-25.
//  Copyright (c) 2014年 XD-XY. All rights reserved.
//

#import "ChooseImageCell.h"

@implementation ChooseImageCell

- (id)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
{
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self) {
        [self makeViews];
    }
    return self;
}

- (void)makeViews{
    _firstIV = [[ChooseImageView alloc] initWithFrame:CGRectMake(0, 2, 104, 104)];
    _firstIV.delegate = self;
    [self.contentView addSubview:_firstIV];

    _secondIV = [[ChooseImageView alloc] initWithFrame:CGRectMake(108, 2, 104, 104)];
    _secondIV.delegate = self;
    [self.contentView addSubview:_secondIV];

    _thirdIV = [[ChooseImageView alloc] initWithFrame:CGRectMake(108*2, 2, 104, 104)];
    _thirdIV.delegate = self;
    [self.contentView addSubview:_thirdIV];

//    _fourthIV = [[ChooseImageView alloc] initWithFrame:CGRectMake(4+79*3, 2, 75, 75)];
//    _fourthIV.delegate = self;
//    [self.contentView addSubview:_fourthIV];
    
}

- (void)getDataWithArray:(NSArray *)dataArray index:(int)index{
    if (!_canChoose) {
        _firstIV.selectBtn.hidden = YES;
        _secondIV.selectBtn.hidden = YES;
        _thirdIV.selectBtn.hidden = YES;
    }
    _firstIV.contentIV.image = nil;
    _secondIV.contentIV.image = nil;
    _thirdIV.contentIV.image = nil;
//    _fourthIV.contentIV.image = nil;
    _firstIV.hidden = NO;
    _secondIV.hidden = NO;
    _thirdIV.hidden = NO;
//    _fourthIV.hidden = NO;

    if (index*3+1 <= dataArray.count) {
        [_firstIV.contentIV sd_setImageWithURL:[NSURL URLWithString:dataArray[index*3][@"Photourl"]] placeholderImage:nil];
        _firstIV.selectBtn.tag = 10000+index*3;
        _firstIV.contentIV.tag = 20000+index*3;
        if ([dataArray[index*3][@"isSelect"] isEqualToString:@"YES"]) {
            _firstIV.selectBtn.selected  = YES;
        }else{
            _firstIV.selectBtn.selected  = NO;
        }
    }else{
        _firstIV.hidden = YES;
    }

    if (index*3+2 <= dataArray.count) {
        [_secondIV.contentIV sd_setImageWithURL:[NSURL URLWithString:dataArray[index*3+1][@"Photourl"]] placeholderImage:nil];
        _secondIV.selectBtn.tag = 10000+index*3+1;
        _secondIV.contentIV.tag = 20000+index*3+1;
        if ([dataArray[index*3+1][@"isSelect"] isEqualToString:@"YES"]) {
            _secondIV.selectBtn.selected  = YES;
        }else{
            _secondIV.selectBtn.selected  = NO;
        }
    }else{
        _secondIV.hidden = YES;
    }

    if (index*3+3 <= dataArray.count) {
        [_thirdIV.contentIV sd_setImageWithURL:[NSURL URLWithString:dataArray[index*3+2][@"Photourl"]] placeholderImage:nil];
        _thirdIV.selectBtn.tag = 10000+index*3+2;
        _thirdIV.contentIV.tag = 20000+index*3+2;
        if ([dataArray[index*3+2][@"isSelect"] isEqualToString:@"YES"]) {
            _thirdIV.selectBtn.selected  = YES;
        }else{
            _thirdIV.selectBtn.selected  = NO;
        }
    }else{
        _thirdIV.hidden = YES;
    }

//    if (index*4+4 <= dataArray.count) {
//        [_fourthIV.contentIV sd_setImageWithURL:[NSURL URLWithString:dataArray[index*4+3][@"Photourl"]] placeholderImage:nil];
//        _fourthIV.selectBtn.tag = 10000+index*4+3;
//        _fourthIV.contentIV.tag = 20000+index*4+3;
//    }else{
//        _fourthIV.hidden = YES;
//    }
}

#pragma mark - ChooseImageCell Delegate
- (void)chooseImageView:(UIButton *)sender{
    [_delegate chooseImage:sender];
}

- (void)gotoDetail:(UIGestureRecognizer *)tap{
    [_delegate gotoDetail:tap];
}



- (void)awakeFromNib
{
    // Initialization code
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated
{
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

@end
